import axios from 'axios';
import { ElMessage } from 'element-plus';

// 创建实例
const request = axios.create({
  baseURL: import.meta.env.VITE_API_BASE_URL, // 从环境变量读取
  timeout: 10000,
  headers: { 'Content-Type': 'application/json' },
});

// 响应拦截器
request.interceptors.response.use(
  (response) => response.data, // 直接返回data字段
  (error) => {
    ElMessage.error({
      message: error.response?.data?.message || error.message,
      type: 'error',
    });
    return Promise.reject(error);
  },
);

export default request;
